import React from 'react'
import store from '../../store/store'
import { incrementAction,
        decrementAction,
        ifOddIncrementAction, 
        waitIncrementAction} 
from '../../store/actions/countAction'

export default function Count() {
  const { count } = store.getState().count
  const incrementHandle = () => {
    store.dispatch(incrementAction(1))
  }
  const decrementHandle = () => {
    store.dispatch(decrementAction(1))
  }
  const ifOddIncrementHandle = () => {
    if (count%2!==0) {
      store.dispatch(ifOddIncrementAction(1))
    }
  }
  const waitIncrementHandle = () => {
      store.dispatch(waitIncrementAction(1))
  }
  
  return (
    <div>
      <h2>我是count要累加的值{count}</h2>
      <button onClick={incrementHandle}>累加</button>
      <button onClick={decrementHandle}>累减</button>
      <button onClick={ifOddIncrementHandle}>如果是奇数才累加</button>
      <button onClick={waitIncrementHandle}>等待两秒在累加</button>
    </div>
  )
}
